<?php

namespace frontend\modules\commission\models;

/**
 * 分销中心会员信息基础
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class UserBranchSearch extends \common\models\user\UserBranch {

    public $rectime = null;

    /**
     * 分销中心会员信息基础
     *
     * @author emhome <emhome@163.com>
     * @since 1.0
     */
    public function buildQuery() {
        $query = static::find()->andWhere([
            'status' => static::STATUS_ACTIVE,
            'member_user_id' => $this->member_user_id,
        ]);
        $query->with(['userMin', 'orders']);
        if ($this->rectime !== null) {
            $query->andWhere(['>', 'created_at', $this->rectime]);
        }
        $query->addOrderBy([
            'created_at' => SORT_DESC,
        ]);
        return $query;
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'user' => 'userMin',
            'orderCount',
            'deleted_at',
            'depend_date' => function() {
                return date('Y-m-d', $this->created_at);
            },
            'created_at'
        ];
    }

}
